#pragma once
#include <carbon/defs.h>

CARBON_NS_BEGIN

template<class T>
struct Allocator {
    template<class U>
    struct rebind { using other = Allocator<U>; };

    T* allocate(size_t n) {
        return static_cast<T*>(::operator new(n * sizeof(T)));
    }

    void deallocate(T* p, size_t) {
        ::operator delete(p);
    }

    template<class U, class... Args>
    void construct(U* p, Args&&... args) {
        ::new(p) U(std::forward<Args>(args)...);
    }

    template<class U>
    void destroy(U* p) {
        p->~U();
    }
}; // struct Allocator

CARBON_NS_END
